package cn.jingzhuan.element.demo.view.fragment

import cn.jingzhuan.element.demo.view.BaseActivity
import cn.jingzhuan.element.demo.view.activity.FeatureLayoutActivity
import cn.jingzhuan.element.demo.view.activity.MusicLayoutActivity
import cn.jingzhuan.element.demo.view.activity.SharedElementActivity
import cn.jingzhuan.element.demo.view.model.ItemDescription
import cn.jingzhuan.element.element.R


class LayoutFragment:HomeFragment(){


    private var layoutItems : MutableList<ItemDescription> =  mutableListOf()

    init {
        layoutItems.add(ItemDescription(FeatureLayoutActivity::class.java,"横向滚动布局",R.mipmap.ic_launcher))
        layoutItems.add(ItemDescription(MusicLayoutActivity::class.java,"经传股声",R.mipmap.ic_launcher))
        layoutItems.add(ItemDescription(SharedElementActivity::class.java,"共享元素切换",R.mipmap.ic_launcher))
    }

    override fun getTitle(): String = resources.getString(R.string.layout)

    override fun getItemAdapter(): ItemAdapter = ItemAdapter(context!!, layoutItems!!)

    var _this = this

    override fun onHomeControlListener(): HomeControlListener = object :HomeControlListener{
        override fun startActivity(activityCla: Class<out BaseActivity>?,title:String) {
            openActivity(activity,activityCla!!,title)
        }
    }

    //    override fun getLayoutId(): Int = R.layout.fragment_layout
////    private lateinit var layoutInflater:

/// AsyncLayoutInflater
//    private var datas : MutableList<String> = mutableListOf()
//
//    override fun onDataBind(savedInstanceState: Bundle?, binding: FragmentLayoutBinding) {
//        binding.toolBar.inflateMenu(R.menu.menu_add)
////        layoutInflater = AsyncLayoutInflater(context!!)
//
//
//        var  adapter = ArrayAdapter<String>(activity,android.R.layout.simple_list_item_1,datas)
//        binding.toolBar.menu.findItem(R.id.action_add).setOnMenuItemClickListener {
//            adapter.add("${System.currentTimeMillis()}")
//            adapter.notifyDataSetChanged()
//            true
//        }
//        Log.i("Element","Item数量：${datas.size}")
//        binding.listView.adapter = adapter
//        binding.listView.onItemClickListener = object : AdapterView.OnItemClickListener{
//            override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
//                Toast.makeText(activity, "你点击的是${position}", Toast.LENGTH_SHORT).show();
//            }
//         }
//
////        binding.toolBar.menu.findItem(R.id.action_add).setOnMenuItemClickListener {
////            // 获取配置中的状态
////            var switch = SettingShared.isEnableThemeDark(context!!)
////            // 切换状态
////            SettingShared.setEnableThemeDark(context!!, !switch)
////            ThemeUtil.notifyThemeApply(activity!!)
////            true
////        }
//    }
//
//
//
//    init {
//        addItems()
//    }
//
//    fun addItems() {
//        datas.add("${System.currentTimeMillis()+1}")
//        datas.add("${System.currentTimeMillis()+2}")
//        datas.add("${System.currentTimeMillis()+3}")
//    }
//
//    internal class ItemView(context: Context) : FrameLayout(context) {
//        private var textView: TextView = TextView(context)
//
//        init {
//            val paddingHor = dp2px(context, 12)
//            val paddingVer = dp2px(context, 6)
//            setPadding(paddingHor, paddingVer, paddingHor, paddingVer)
//            addView(textView, FrameLayout.LayoutParams(
//                    ViewGroup.LayoutParams.MATCH_PARENT, dp2px(context, 64)))
//            val paddingTvHor = dp2px(context, 16)
//            textView.setPadding(paddingTvHor, 0, paddingTvHor, 0)
//            textView.gravity = Gravity.CENTER_VERTICAL
//        }
//
//        fun dp2px(context: Context,dp: Int) :Int =  (context.resources.displayMetrics.density * dp + 0.5).toInt()
//
//        fun setText(text: String) {
//            textView.text = text
//        }
//    }

//    internal class SimpleAdapter(context: Context,datas:MutableList<String>):BaseAdapter() {
//
//        private var context:Context = context
//        private var datas = datas
//
//        override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
//            Log.i("Element","获取view...")
//            val itemView: ItemView
//            if (convertView == null) {
//                itemView = ItemView(context)
//                itemView.layoutParams = AbsListView.LayoutParams(
//                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
//            } else {
//                itemView = convertView as ItemView
//            }
//            itemView.setText(getItem(position).toString())
//            Log.i("Element","获取view:${getItem(position)}")
//            return itemView
//        }
//
//        override fun getItem(position: Int): Any = datas.get(position)
//
//        override fun getItemId(position: Int): Long = position.toLong()
//
//        override fun getCount(): Int = datas.size
//
//    }
}